{ INFORMATICS.MCCME.RU
  Problem statement: http://informatics.mccme.ru/moodle/mod/statements/view3.php?chapterid=3397
  Verdict: Accepted
}
var n,m,i,x,c,r,j,y:longint; a,h,q:array[0..110] of longint; t:array[0..110,0..110] of longint;
procedure qsort(l,r:longint);
var i,j,x,y:longint;
begin
i:=l;
j:=r;
x:=h[q[(l+r) div 2]];
repeat
  while h[q[i]]<x do inc(i);
  while h[q[j]]>x do dec(j);
  if i<=j then begin
    y:=q[i];
    q[i]:=q[j];
    q[j]:=y;
    inc(i);
    dec(j);
  end;
until i>j;
if l<j then qsort(l,j);
if i<r then qsort(i,r);
end;
begin
assign(input,'input.txt');
assign(output,'output.txt');
reset(input);
rewrite(output);
read(n,m);
fillchar(t,sizeof(t),0);
y:=0;
for i:=1 to m do begin
    read(a[i]);
		if y<a[i] then y:=a[i];
end;
writeln(y*n);
c:=1;
for i:=1 to m do begin
    x:=1;
    r:=0;
    j:=c;
    while x<=n do begin
					t[j][i]:=r;
					inc(r,y);
          inc(x);
          j:=j mod n+1;
    end;
    inc(c);
end;
for i:=1 to n do begin
    writeln;
    for j:=1 to m do h[j]:=t[i][j];
    for j:=1 to m do q[j]:=j;
    qsort(1,m);
    for j:=1 to m do
        writeln(q[j],' ',h[q[j]]);
end;
end.